#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left, self.right = None, None


class Solution:
    """
    @param inorder: A list of integers that inorder traversal of a tree
    @param preorder: A list of integers that preorder traversal of a tree
    @return: Root of a tree
    """
    def buildTree(self, preorder, inorder):
        # for root in reversed(preorder):
        return self.construct(preorder, inorder)

    def construct(self, preorder, inorder):
        if not inorder:
            return None

        assert preorder

        root_v = preorder.pop(0)
        root = TreeNode(root_v)

        left_data, right_data = self.split(inorder, root_v)
        root.left, root.right = \
                self.construct(preorder, left_data), self.construct(preorder, right_data)
        return root

    def split(self, data, root_v):
        for i, v in enumerate(data):
            if v == root_v:
               return data[0:i], data[i+1:]


def main():
    print("start main")

if __name__ == "__main__":
    main()
